import 'dart:math';

import 'package:flutter/material.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/theme/hc_common_theme.dart';
import 'package:hc_ui/theme/hc_title_theme.dart';
import 'package:hc_ui/utils/hc_gradient_util.dart';
import 'package:hc_ui/utils/hc_number_util.dart';
import 'package:hc_ui/widget/image/hc_image.dart';
import 'package:hc_ui/widget/progress/hc_progress.dart';
import 'package:hc_ui/widget/space/hc_space.dart';
import 'package:hc_ui/widget/title/hc_title.dart';

class HcProgressPage extends StatefulWidget {
  const HcProgressPage({super.key});

  @override
  State<HcProgressPage> createState() => _HcProgressPageState();
}

class _HcProgressPageState extends State<HcProgressPage> {
  double value = 0;

  void _incrementCounter() {
    setState(() {
      value = value == 100 ? 0 : min(100, max(0, value + 10));
    });
    print("当前 index${value} ");
  }

  @override
  Widget build(BuildContext context) {
    HcCommonTheme theme = HcCustomerConfig().allTheme.commonTheme;
    return Scaffold(
      backgroundColor: theme.fillPageColor,
      appBar: AppBar(
        title: const Text("HcProgressPage"),
      ),
      body: ListView(
        padding: EdgeInsets.symmetric(
            vertical: theme.commonTheme.hSpacingPage,
            horizontal: theme.commonTheme.hSpacingPage),
        children: [
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(0)),
            subtitle: "左上角显示/圆角",
          ),
          HcProgress(
            radius: 20,
            spacing: 8,
            textPosition: HcProgressTextPosition.leftTop,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "上部居中显示/渐变",
          ),
          HcProgress(
            gradient: HcGradientUtil.generateLinearGradient(
                colors: [Colors.purple, Colors.cyanAccent]),
            textPosition: HcProgressTextPosition.topCenter,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "右上角展示文字/分段展示颜色",
          ),
          HcProgress(
            piecewiseList: [
              HcPiecewiseColorItem(percentage: 0, color: Colors.purple),
              HcPiecewiseColorItem(percentage: 20, color: Colors.pinkAccent),
              HcPiecewiseColorItem(percentage: 60, color: Colors.yellow),
              HcPiecewiseColorItem(percentage: 80, color: Colors.green),
              HcPiecewiseColorItem(percentage: 100, color: Colors.cyanAccent),
            ],
            textPosition: HcProgressTextPosition.rightTop,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "左侧展示文字/展示条纹样式",
          ),
          HcProgress(
            radius: 0,
            showStripe: true,
            textPosition: HcProgressTextPosition.centerLeft,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "右侧展示文字/自定义进度按钮",
          ),
          HcProgress(
            activeIcon: const HcImage(
              src: 'assets/images/run.png',width: 20,height: 14,
            ),
            textPosition: HcProgressTextPosition.centerRight,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "左下展示文字/自定义文字",
          ),
          HcProgress(
            tips:
                "当前仅剩:${double.parse(HcNumberUtil.formatNum(num: 100 - value, position: 1))}%",
            textPosition: HcProgressTextPosition.leftBottom,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "下部居中展示文字/扩大文字与进度条间隔",
          ),
          HcProgress(
            spacing: 1,
            textPosition: HcProgressTextPosition.bottomCenter,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "右下展示文字/增加边框",
          ),
          HcProgress(
            radius: 20,
            border: Border.all(color: Colors.cyan, width: 1),
            textPosition: HcProgressTextPosition.rightBottom,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "居中展示 /设置背景",
          ),
          HcProgress(
            radius: 100,
            tips: "当前仅剩:${100 - value}%",
            tipsStyle: const TextStyle(fontSize: 12, color: Colors.cyan),
            border: Border.all(color: Colors.cyan, width: 1),
            color: Colors.cyan.withOpacity(0.1),
            bgColor: Colors.white,
            textPosition: HcProgressTextPosition.center,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "进度条内部展示文字",
          ),
          HcProgress(
            radius: 0,
            color: Colors.brown,
            textPosition: HcProgressTextPosition.inside,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "不展示文字",
          ),
          HcProgress(
            radius: 0,
            textPosition: HcProgressTextPosition.none,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "内部跟随",
          ),
          HcProgress(
            radius: 0,
            textPosition: HcProgressTextPosition.insideFlow,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "上部跟随",
          ),
          HcProgress(
            radius: 0,
            textPosition: HcProgressTextPosition.topFlow,
            value: value,
          ),
          HcTitle(
            themeData: HcTitleTheme(titlePadding: const EdgeInsets.all(1)),
            subtitle: "下部跟随",
          ),
          HcProgress(
            value: value,
            activeIcon: Icon(Icons.abc_outlined),
            textPosition: HcProgressTextPosition.bottomFlow,
          ),
          const HcSpace(
            height: 30,
          )
        ],
      ),

      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
